package com.west.common.base.fragment;

import android.support.annotation.DrawableRes;
import android.support.annotation.LayoutRes;
import android.support.annotation.StringRes;
import android.view.View;
import android.view.ViewStub;

import com.west.common.common.R;
import com.west.common.widget.TitleBar;


public abstract class BaseTitleFragment extends BaseFragment {

    protected TitleBar mTitleBar;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_base_title;
    }

    @Override
    protected void onBindViewBefore(View root) {
        super.onBindViewBefore(root);
        // on before onBindViewBefore call
        ViewStub stub = (ViewStub) root.findViewById(R.id.lay_content);
        stub.setLayoutResource(getContentLayoutId());
        stub.inflate();
    }

    @Override
    protected void initWidget(View root) {
        super.initWidget(root);
        mTitleBar = (TitleBar) root.findViewById(R.id.nav_title_bar);
        mTitleBar.setTitle(getTitleRes());
        mTitleBar.setTitleIcon(getTitleIconRes());
        mTitleBar.setLeftIcon(getLeftIconRes());
        mTitleBar.setRightIcon(getRightIconRes());
        mTitleBar.setRightOnClickListener(getRightIconOnClickLienter());
        mTitleBar.setLeftIconOnClickListener(getLeftIconOnClickListener());
        mTitleBar.setRightTitle(getRightTitle());
        mTitleBar.setRightTitleOnClickListener(getRightIconOnClickLienter());
    }

    protected abstract @LayoutRes int getContentLayoutId();

    @StringRes
    protected abstract int getTitleRes();

    @DrawableRes
    protected abstract int getTitleIconRes();

    @DrawableRes
    protected abstract int getRightIconRes();

    @DrawableRes
    protected abstract int getLeftIconRes();

    protected View.OnClickListener getLeftIconOnClickListener() {
        return null;
    }

    protected View.OnClickListener getRightIconOnClickLienter() {
        return null;
    }

    protected void setSearchViewVisible(boolean show){
        mTitleBar.setSearchViewVisible(show);
    }

    protected void setTabLayoutVisible(boolean isHide){
        mTitleBar.setTabLayoutVisible(isHide);
    }

    protected void setUnReadCount(int count){
        mTitleBar.setUnReadCount(count);
    }

    protected void setTitleBarBg(int color){
        mTitleBar.setBackgroundColor(color);
    }

    protected void setTitleColor(int color){
        mTitleBar.setTitleColor(color);
    }

    protected void setRightIconRes(@DrawableRes int icon){
        mTitleBar.setRightIcon(icon);
    }

    protected void setLeftIconRes(@DrawableRes int icon){
        mTitleBar.setLeftIcon(icon);
    }

    protected void setRightTitle(String str){
        mTitleBar.setRightTitle(str);
    }

    protected String getRightTitle(){
        return mTitleBar.getRightTitle();
    }

    protected View.OnClickListener setRightTitleOnClickListener(View.OnClickListener listener){
        return null;
    }

}
